package com.king01.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.king01.dao.BranchDao;
import com.king01.entity.Branch;
import com.king01.entity.Role;
import com.king01.entity.Staff;
import com.king01.service.BranchService;
import com.king01.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author ：lqs
 * @date ：Created in 2023/9/27 9:52
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class BranchServiceImpl implements BranchService {
    @Autowired
    private BranchDao branchDao;
    @Autowired
    private HttpSession session;


    //查询店铺表
    @Override
    public Result allBranch() {
        Staff staff =(Staff) session.getAttribute("staff");
        SessionVo sessionVo = new SessionVo(staff.getStaffid(), staff.getBranchid());
        List<Branch> branches = branchDao.allBranch(sessionVo);
        return new Result(200,"查询了店铺表的全部数据",branches);
    }

    @Override
    public Result allBranch2() {
        Staff staff =(Staff) session.getAttribute("staff");
        List<Branch> branches = branchDao.allBranch2(staff.getBranchid());
        return new Result(200,"查询了店铺表的全部数据",branches);
    }

    public Result selectAll() {
        Staff staff =(Staff) session.getAttribute("staff");
        List<Branch> list=branchDao.findAll(staff.getStaffid());
        return new Result(200,"查询成功",list);
    }
    //查询所有店铺的信息
    @Override
    public Result selectAllBranchAndStaff() {
        return null;
    }

    @Override
    public PageBean<Branch> selectAllBranchAndStaff(Integer currentPage, Integer pageSize, BranchVo branchVo) {
        //分页插件
        PageHelper.startPage(currentPage, pageSize);
        List<Branch> branches = branchDao.selectAllBranchAndStaff(branchVo);
        PageInfo<Branch> pageInfo = new PageInfo<>(branches);
        return new PageBean<Branch>(pageInfo.getTotal(), pageInfo.getList());
    }

    //模糊查询
    @Override
    public Result queryBranchInfoBybranchname(Branch branchname) {
        List<Branch> branches = branchDao.queryBranchInfoBybranchname(branchname);
        return new Result(200,"查询成功",branches);
    }

    //添加
    @Override
    public Integer insertNewBranch(Branch branch) {
        Integer integer = branchDao.insertNewBranch(branch);
        return integer;
    }

    //修改
    @Override
    public Integer UpdateBranch(Branch branch) {
        Integer integer = branchDao.UpadteBranch(branch);
        return integer;
    }

    @Override
    public Result adjustBranch(Branch branch) {

        if (branch.getState()==1){
            branch.setState(2);
            Integer integer = branchDao.adjustBranch(branch);
            return new Result(200,"整顿成功",null);

        }else {
            branch.setState(1);
            Integer integer = branchDao.adjustBranch(branch);
            return new Result(200,"整顿成功",null);
        }

    }

    @Override
    public Integer upStaff(Staff02vo staff02vo) {
        Integer integer = branchDao.upStaff(staff02vo);
        return integer;
    }

    @Override
    public Integer upBranch(Staff02vo staff02vo) {
        Integer integer = branchDao.upBranch(staff02vo);
        return integer;
    }

    @Override
    public List<Staff> selectAll2() {
        List<Staff> list = branchDao.selectAll();
        return list;
    }

    @Override
    public Integer updateDate(Staff staff) {
        Integer integer = branchDao.updateDate(staff);
        return integer;
    }

    @Override
    public Integer updateStaff(Staff staff) {
        Integer integer = branchDao.updateStaff(staff);
        return integer;
    }

    @Override
    public Result selectDeptName(Integer branchid) {
        String deptname = branchDao.findDeptNameByStaffId(branchid);
        return new Result(200,"查询部门名成功",deptname);
    }


}

